package com.cheyunkeji.er.adapter.fastevaluate;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.adapter.MyBaseAdapter;
import com.cheyunkeji.er.bean.fast_evaluate.PrevEvaluateRecord;
import com.cheyunkeji.er.utils.TimeUtils;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Michael on 2017/3/31 14:19.
 */

public class PrevEvaluateRecordsAdapter extends MyBaseAdapter {

    public static final int EVALUATE_STATE_WAIT_PUSH = 1;
    public static final int EVALUATE_STATE_PUSHED = 2;
    public static final int EVALUATE_STATE_ON_PROCESS = 3;
    public static final int EVALUATE_STATE_UPLOADED = 4;

    public PrevEvaluateRecordsAdapter(ArrayList<PrevEvaluateRecord> dataList, Context context) {
        super(dataList, context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.er_prev_evaluate_records_item, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        PrevEvaluateRecord bean = (PrevEvaluateRecord) dataList.get(position);
        holder.tvName.setText(bean.getBeforeBrandName());
        holder.tv_car_vin.setText(String.format(context.getResources().getString(R.string.car_model_vin), bean.getVin()));
        holder.tvPalateNumber.setText(bean.getPlate());
        holder.tvCarModel.setText(String.format(context.getResources().getString(R.string.car_model), bean.getBeforeModelName()));
        holder.tvEvaluateDate.setText(String.format(context.getResources().getString(R.string.prev_evaluate_date), TimeUtils.millis2StringWithoutHMS(Long.valueOf(String.valueOf(bean.getDateline()) + "000"))));

        return convertView;

    }

    //设置评估记录当前状态
    private void setCurrentState(TextView tvEvaluateState, int evaluateState) {

        switch (evaluateState) {
            case EVALUATE_STATE_WAIT_PUSH:
                tvEvaluateState.setText(R.string.wait_push);
                tvEvaluateState.setTextColor(context.getResources().getColor(R.color.wait_push));
                break;
            case EVALUATE_STATE_PUSHED:
                tvEvaluateState.setText(R.string.pushed);
                tvEvaluateState.setTextColor(context.getResources().getColor(R.color.pushed));
                break;
            case EVALUATE_STATE_ON_PROCESS:
                tvEvaluateState.setText(R.string.evaluate_on_process);
                tvEvaluateState.setTextColor(context.getResources().getColor(R.color.blue_2));
                break;
            case EVALUATE_STATE_UPLOADED:
                tvEvaluateState.setText(R.string.uploaded);
                tvEvaluateState.setTextColor(context.getResources().getColor(R.color.uploaded));
                break;

            default:
                break;
        }

    }

    static class ViewHolder {
        @BindView(R.id.tv_name)
        TextView tvName;
//        @BindView(R.id.tv_contact_number)
//        TextView tvContactNumber;
        @BindView(R.id.tv_palate_number)
        TextView tvPalateNumber;
        @BindView(R.id.tv_car_model)
        TextView tvCarModel;
        @BindView(R.id.tv_evaluate_date)
        TextView tvEvaluateDate;
        @BindView(R.id.tv_car_vin)
        TextView tv_car_vin;

//        @BindView(R.id.tv_evaluate_state)
//        TextView tvEvaluateState;
//        @BindView(R.id.tv_sell_state)
//        TextView tvSellState;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
